import matplotlib
import matplotlib.pyplot as plt
import pandas as pd

def create_png(k):
    matplotlib.rcParams['font.family'] = 'SimHei'
    # 读取 Excel 文件中的数据
    df = pd.read_excel('output/diploma.xlsx', sheet_name='base')
    # 删除第一列
    df = df.iloc[1:, 1:]
    y1_deg_influence = []
    y2_deg_influence = []
    y3_deg_influence = []
    y1_PR_influence = []
    y1_PRTH_influence = []
    y1_PRDD_influence = []
    y2_PR_influence = []
    y2_PRTH_influence = []
    y2_PRDD_influence = []
    y3_PR_influence = []
    y3_PRTH_influence = []
    y3_PRDD_influence = []

    for i in range(5):
        data = df.iloc[i, 0]
        y1_deg_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 1]
        y1_PR_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 2]
        y1_PRTH_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 3]
        y1_PRDD_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 4]
        y2_deg_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 5]
        y2_PR_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 6]
        y2_PRTH_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 7]
        y2_PRDD_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 8]
        y3_deg_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 9]
        y3_PR_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 10]
        y3_PRTH_influence.append(data)


    for i in range(5):
        data = df.iloc[i, 11]
        y3_PRDD_influence.append(data)

    x = [1*k, 2*k, 3*k, 4*k, 5*k]

    # 第一组图
    fig, axs = plt.subplots(2, 3, figsize=(20, 10))
    fig.suptitle('基于社区划分的影响力最大化研究')

    # 第一个子图
    axs[0, 0].plot(x, y1_deg_influence, marker='x', markersize=8, linestyle='-', label='Deg')
    axs[0, 0].plot(x, y1_PR_influence, marker='o', markersize=8, linestyle='-', label='PageRank')
    axs[0, 0].plot(x, y1_PRTH_influence, marker='s', markersize=8, linestyle='-', label='PRCP')
    axs[0, 0].plot(x, y1_PRDD_influence, marker='^', markersize=8, linestyle='-', label='PRDCP')
    axs[0, 0].set_xlabel('种子节点数量')
    axs[0, 0].set_ylabel('影响力')
    axs[0, 0].set_title('Email')
    axs[0, 0].legend()

    # 第二个子图
    axs[0, 1].plot(x, y2_deg_influence, marker='x', markersize=8, linestyle='-', label='Deg')
    axs[0, 1].plot(x, y2_PR_influence, marker='o', markersize=8, linestyle='-', label='PageRank')
    axs[0, 1].plot(x, y2_PRTH_influence, marker='s', markersize=8, linestyle='-', label='PRCP')
    axs[0, 1].plot(x, y2_PRDD_influence, marker='^', markersize=8, linestyle='-', label='PRDCP')
    axs[0, 1].set_xlabel('种子节点数量')
    axs[0, 1].set_ylabel('影响力')
    axs[0, 1].set_title('Marvel')
    axs[0, 1].legend()

    axs[0, 2].plot(x, y3_deg_influence, marker='x', markersize=8, linestyle='-', label='Deg')
    axs[0, 2].plot(x, y3_PR_influence, marker='o', markersize=8, linestyle='-', label='PageRank')
    axs[0, 2].plot(x, y3_PRTH_influence, marker='s', markersize=8, linestyle='-', label='PRCP')
    axs[0, 2].plot(x, y3_PRDD_influence, marker='^', markersize=8, linestyle='-', label='PRDCP')
    axs[0, 2].set_xlabel('种子节点数量')
    axs[0, 2].set_ylabel('影响力')
    axs[0, 2].set_title('Github')
    axs[0, 2].legend()

    # 读取 Excel 文件中的数据
    df = pd.read_excel('output/diploma.xlsx', sheet_name='COBase')
    # 删除第一列
    df = df.iloc[1:, 1:]
    y1_COdeg_influence = []
    y2_COdeg_influence = []
    y3_COdeg_influence = []
    y1_COPR_influence = []
    y1_COPRTH_influence = []
    y1_COPRDD_influence = []
    y2_COPR_influence = []
    y2_COPRTH_influence = []
    y2_COPRDD_influence = []
    y3_COPR_influence = []
    y3_COPRTH_influence = []
    y3_COPRDD_influence = []

    for i in range(5):
        data = df.iloc[i, 0]
        y1_COdeg_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 1]
        y1_COPR_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 2]
        y1_COPRTH_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 3]
        y1_COPRDD_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 4]
        y2_COdeg_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 5]
        y2_COPR_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 6]
        y2_COPRTH_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 7]
        y2_COPRDD_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 8]
        y3_COdeg_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 9]
        y3_COPR_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 10]
        y3_COPRTH_influence.append(data)

    for i in range(5):
        data = df.iloc[i, 11]
        y3_COPRDD_influence.append(data)
    # 第一个子图
    axs[1, 0].plot(x, y1_COdeg_influence, marker='x', markersize=8, linestyle='-', label='CoDeg')
    axs[1, 0].plot(x, y1_COPR_influence, marker='o', markersize=8, linestyle='-', label='CoPageRank')
    axs[1, 0].plot(x, y1_COPRTH_influence, marker='s', markersize=8, linestyle='-', label='CoPRCP')
    axs[1, 0].plot(x, y1_COPRDD_influence, marker='^', markersize=8, linestyle='-', label='CoPRDCP')
    axs[1, 0].set_xlabel('种子节点数量')
    axs[1, 0].set_ylabel('影响力')
    axs[1, 0].set_title('Email')
    axs[1, 0].legend()

    # 第二个子图
    axs[1, 1].plot(x, y2_COdeg_influence, marker='x', markersize=8, linestyle='-', label='CoDeg')
    axs[1, 1].plot(x, y2_COPR_influence, marker='o', markersize=8, linestyle='-', label='CoPageRank')
    axs[1, 1].plot(x, y2_COPRTH_influence, marker='s', markersize=8, linestyle='-', label='CoPRCP')
    axs[1, 1].plot(x, y2_COPRDD_influence, marker='^', markersize=8, linestyle='-', label='CoPRDCP')
    axs[1, 1].set_xlabel('种子节点数量')
    axs[1, 1].set_ylabel('影响力')
    axs[1, 1].set_title('Marvel')
    axs[1, 1].legend()

    # 第三个子图
    axs[1, 2].plot(x, y3_COdeg_influence, marker='x', markersize=8, linestyle='-', label='CoDeg')
    axs[1, 2].plot(x, y3_COPR_influence, marker='o', markersize=8, linestyle='-', label='CoPageRank')
    axs[1, 2].plot(x, y3_COPRTH_influence, marker='s', markersize=8, linestyle='-', label='COPRCP')
    axs[1, 2].plot(x, y3_COPRDD_influence, marker='^', markersize=8, linestyle='-', label='COPRDCP')
    axs[1, 2].set_xlabel('种子节点数量')
    axs[1, 2].set_ylabel('影响力')
    axs[1, 2].set_title('Github')
    axs[1, 2].legend()

    plt.show()

    fig.savefig("output/diploma.png")
